﻿using EntityFrameworks.Data.Core;
using 为web添加unity.caching在controller中注入.DomainModels;
using 为web添加unity.caching在controller中注入.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using 为web添加unity.caching在controller中注入.Repository;
namespace 为web添加unity.caching在controller中注入.Models
{
    using BLL;
    public class OrderController : BaseController
    {
        protected EEE114Entities db = new EEE114Entities();
        IOrderService orderService;
        IOrderRepository iOrderRepository;
        IUserRepository iUserRepository;

        public OrderController()
        {
            orderService = GetService<IOrderService>();
            iOrderRepository = GetService<IOrderRepository>();
            iUserRepository = GetService<IUserRepository>();
        }
        //
        // GET: /Order/

        public ActionResult Index()
        {

            return View();
        }

        public PartialViewResult Order_Hot()
        {
            var model = from data1 in db.Order_Info
                        join data2 in db.Order_Detail on data1.OrderID equals data2.OrderID into list
                        select new Order_Hot
                        {
                            OrderID = data1.OrderID,
                            OrderTime = data1.BuyTime.Value,
                            ProductIDArr = list.Select(i => i.ProductID),
                        };
            //得到真实数据
            var viewModel = model.Take(10).ToList().Select(i => new ViewModels.Order_Hot
            {
                OrderID = i.OrderID,
                OrderTime = i.OrderTime,
                ProductIDStr = string.Join(",", i.ProductIDArr),
            });
            return PartialView(viewModel);
        }



        public PartialViewResult Order_Total(int page = 1)
        {
            //   Repository.IOrderRepository iOrderRepository = ServiceLocator.Instance.GetService<IOrderRepository>();
            // var model = iOrderRepository.Fetch(i => i.Desc(j => j.OrderID), i => i.OrderID != 0, page, 3);
            var model = orderService.GetOrder(page, 3);
            return PartialView(model);
        }

        public PartialViewResult User_Info(int page = 1)
        {

            var linq = from data1 in iOrderRepository.GetModel()
                       join data2 in iUserRepository.GetModel() on data1.UserID equals data2.UserID
                       select data1;

            var model = iUserRepository.Fetch(i => i.UserID != 0, page, 3);
            return PartialView(model);
        }
    }
}
